////////////////////////////////////////////// signatory party info///////////////////////////////////////////
var signatoryPartyPanel =new Ext.form.FormPanel({
	id:'SignatoryPartyPanel',
	frame:true,//圆角和浅蓝色背景
	blankText:'不允许为空',
	labelAlign:'right',
	monitorValid:true,
	defaults:{
		labelWidth:150
	},
	items:[
	{
		xtype:'textfield',
		id:'signatory_party_name',
		fieldLabel:'name',
		name:'signatoryparty_attr_name',
		width:100,
		enableKeyEvents:true,
		allowBlank:false
	}
	,{
		xtype:'textfield',
		id:'signatory_party_type',
		fieldLabel:'Party Type',
		name:'signatoryparty_attr_name',
		width:100,
		enableKeyEvents:true,
		readOnly:true
	}
	,{
		xtype:'fieldset',
        title: 'Contact',
        collapsible: true,
        autoHeight:true,
        width:420,
        defaults: {width: 200},
        defaultType: 'textfield',
        items :[
		{
			xtype:'textfield',
			id:'signatory_party_city',
			name:'city_content',
			fieldLabel:'City',
			allowblank:false,
			enableKeyEvents:true
		}
		,{
			xtype:'textfield',
			id:'signatory_party_street',
			name:'street_content',
			fieldLabel:'Street',
			allowblank:false,
			enableKeyEvents:true
		}
        ]
	}
	,{
		xtype:'fieldset',
        title: 'Action',
        collapsible: true,
        autoHeight:true,
        width:420,
        defaults: {width: 200},
        defaultType: 'textfield',
        items :[
		{
			xtype:'textfield',
			id:'action_name',
			name:'action_attr_name',
			fieldLabel:'name',
			allowblank:false,
			enableKeyEvents:true
		}
		,{
			xtype:'textfield',
			id:'action_wsdl_file',
			fieldLabel:'WSDLFile',
			name:'wsdlfile_content',
			enableKeyEvents:true
		}
		,{
			xtype:'textfield',
			id:'action_soap_binding',
			fieldLabel:'SOAPBindingName',
			name:'soapbindingname_content',
			enableKeyEvents:true
		}
		,{
			xtype:'textfield',
			id:'action_soap_operation',
			fieldLabel:'SOAPOperationName',
			name:'soapoperationname_content',
			allowblank:true,
			enableKeyEvents:true
		}
        ]
	}
	],
	buttons:[
 	{
 		ref:'SignatoryPartyBtn',
 		formBind:true,
 		height : 20,
 		width : 50,
 		action: 'add',
 		text : '添加',
 		handler: function() {
 			//关闭window，在tree上添加节点
 			var name=Ext.getCmp('signatory_party_name').getValue();
			var type=Ext.getCmp('signatory_party_type').getValue();
			var city=Ext.getCmp('signatory_party_city').getValue();
			var street=Ext.getCmp('signatory_party_street').getValue();
			var action_name=Ext.getCmp('action_name').getValue();
			var action_wsdl_file=Ext.getCmp('action_wsdl_file').getValue();
			var action_soap_binding=Ext.getCmp('action_soap_binding').getValue();
			var action_soap_operation=Ext.getCmp('action_soap_operation').getValue();			
 			
			var partyAttr=new HashMap();
			partyAttr.put('name',name);
			var actionAttr=new HashMap();
			actionAttr.put('name',action_name);
			actionAttr.put('partyName',name);
			actionAttr.put('xsi:type','WSDLSOAPActionDescriptionType');
 			
 			var streetNode=new Ext.tree.TreeNode({
 				id:idgen.newId(),
				text:'Street ['+street+']',
				tag:'Street',
				type:'Street',
				content:street
 			});
 			
 			var cityNode=new Ext.tree.TreeNode({
 				id:idgen.newId(),
				text:'City ['+city+']',
				tag:'City',
				type:'City',
				content:city
 			});
 			
 			var contactNode=new Ext.tree.TreeNode({
 				id:idgen.newId(),
				text : "Contact",
				tag : "Contact",
				type:"Contact",
				attributes : new HashMap()
 			});
 			contactNode.appendChild(streetNode);
 			contactNode.appendChild(cityNode);
 			
 			var wsdlFileNode=new Ext.tree.TreeNode({
 				id:idgen.newId(),
				text:'WSDLFile ['+action_wsdl_file+']',
				tag:'WSDLFile',
				type:'WSDLFile',
				content:action_wsdl_file
 			});
 			
 			var soapBindingName=new Ext.tree.TreeNode({
 				id:idgen.newId(),
				text:'SOAPBindingName ['+action_soap_binding+']',
				tag:'SOAPBindingName',
				type:'SOAPBindingName',
				content:action_soap_binding
 			});
 			
 			var soapOperationName=new Ext.tree.TreeNode({
 				id:idgen.newId(),
				text:'SOAPOperationName ['+action_soap_operation+']',
				tag:'SOAPOperationName',
				type:'SOAPOperationName',
				content:action_soap_operation
 			});
 			
 			var actionNode=new Ext.tree.TreeNode({
 				id:idgen.newId(),
				text:'Action ['+action_name+']',
				tag:'Action',
				type:'Action',
				attributes:actionAttr
 			});
 			actionNode.appendChild(wsdlFileNode);
 			actionNode.appendChild(soapBindingName);
 			actionNode.appendChild(soapOperationName);
 			
 			var partyNode=new Ext.tree.TreeNode({
 				text:type+' ['+name+']',
 				name:name,
 				tag:type,
 				type:'SignatoryParty',
 				attributes:partyAttr,
 				listeners:{
 					'contextmenu':function(node,e){
 						tree.selectedNode=node;
 						nodeOperationMenu.showAt(e.getXY());
 					}
 				}
 			});
 			partyNode.appendChild(contactNode);
 			partyNode.appendChild(actionNode);
 			
 			if(this.action=='add'){
 				partiesNode.appendChild(partyNode); 	 			
 			}else if(this.action=='edit'){
 				tree.selectedNode.remove();
 				partiesNode.appendChild(partyNode);
 			}
 			
 			signatoryPartyWin.hide();	
 		}
 	}
 	],
 	genNode:function(){
 		
 	}
});

var signatoryPartyWin=new Ext.Window({
	id:'SignatoryPartyWin',
	closeAction : 'hide', //这个很重要，为了防止关闭窗口后无法打开
	resizable : true,
	layout : 'fit',
	closable:true, 
	height:450,
	width:450,
	modal:true,
	items:[
	    signatoryPartyPanel
	]
});

////////////////////////////////////////////// supporting party info///////////////////////////////////////////
var supportingPartyPanel =new Ext.form.FormPanel({
	id:'SupportingPartyPanel',
	frame:true,//圆角和浅蓝色背景
	blankText:'不允许为空',
	labelAlign:'right',
	monitorValid:true,
	defaults:{
		labelWidth:150
	},
	items:[
	{
		xtype:'textfield',
		id:'supporting_party_name',
		fieldLabel:'name',
		name:'supportingparty_attr_name',
		width:100,
		enableKeyEvents:true,
		allowBlank:false
	}
	,{
		xtype:'combo',
		id:'supporting_party_role',
		fieldLabel:'Party Role',
		name:'supportingparty_attr_role',
	    store :new Ext.data.SimpleStore({   
	        fields: ['text'],
	        data: [
	            ['MeasurementService']
	        	,['ManagementService']
	        	,['ConditionEvaluationService']
	        ]   
	    }),
	    valueField :"text",
		displayField :"text",
		editable:false,
		forceSelection :true,
		typeAhead :true,
		triggerAction :'all',
		selectOnFocus :true,// 用户不能自己输入,只能选择列表中有的记录
		allowBlank :false,
		mode: 'local',
		emptyText:'请选择Party Role'
	}
	,{
		xtype:'fieldset',
        title: 'Contact',
        collapsible: true,
        autoHeight:true,
        width:420,
        defaults: {width: 200},
        defaultType: 'textfield',
        items :[
		{
			xtype:'textfield',
			id:'supporting_party_city',
			name:'city_content',
			fieldLabel:'City',
			allowblank:false,
			enableKeyEvents:true
		}
		,{
			xtype:'textfield',
			id:'supporting_party_street',
			name:'street_content',
			fieldLabel:'Street',
			allowblank:false,
			enableKeyEvents:true
		}
        ]
	}
	,{
		xtype:'fieldset',
        title: 'Action',
        collapsible: true,
        autoHeight:true,
        width:420,
        defaults: {width: 200},
        defaultType: 'textfield',
        items :[
		{
			xtype:'textfield',
			id:'supporting_action_name',
			name:'action_attr_name',
			fieldLabel:'name',
			allowblank:false,
			enableKeyEvents:true
		}
		,{
			xtype:'textfield',
			id:'supporting_action_wsdl_file',
			fieldLabel:'WSDLFile',
			name:'wsdlfile_content',
			enableKeyEvents:true
		}
		,{
			xtype:'textfield',
			id:'supporting_action_soap_binding',
			fieldLabel:'SOAPBindingName',
			name:'soapbindingname_content',
			enableKeyEvents:true
		}
		,{
			xtype:'textfield',
			id:'supporting_action_soap_operation',
			fieldLabel:'SOAPOperationName',
			name:'soapoperationname_content',
			allowblank:true,
			enableKeyEvents:true
		}
        ]
	}
	],
	buttons:[
 	{
 		ref:'SopportingPartyBtn',
 		formBind:true,
 		height : 20,
 		width : 50,
 		text : '添加',
 		handler: function() {
 			//关闭window，在tree上添加节点
 			var name=Ext.getCmp('supporting_party_name').getValue();
 			var role=Ext.getCmp('supporting_party_role').getValue();
			var type='SupportingParty';
			var city=Ext.getCmp('supporting_party_city').getValue();
			var street=Ext.getCmp('supporting_party_street').getValue();
			var action_name=Ext.getCmp('supporting_action_name').getValue();
			var action_wsdl_file=Ext.getCmp('supporting_action_wsdl_file').getValue();
			var action_soap_binding=Ext.getCmp('supporting_action_soap_binding').getValue();
			var action_soap_operation=Ext.getCmp('supporting_action_soap_operation').getValue();
			
 			
			var partyAttr=new HashMap();
			partyAttr.put('name',name);
			partyAttr.put('role',role);
			var actionAttr=new HashMap();
			actionAttr.put('name',action_name);
			actionAttr.put('partyName',name);
			actionAttr.put('xsi:type','WSDLSOAPActionDescriptionType');		
 			
 			
 			var streetNode=new Ext.tree.TreeNode({
 				id:idgen.newId(),
				text:'Street ['+street+']',
				tag:'Street'
 			});
 			
 			var cityNode=new Ext.tree.TreeNode({
 				id:idgen.newId(),
				text:'City ['+city+']',
				tag:'City'
 			});
 			
 			var contactNode=new Ext.tree.TreeNode({
 				id:idgen.newId(),
				text : "Contact",
				tag : "Contact",
				attributes : new HashMap()
 			});
 			contactNode.appendChild(streetNode);
 			contactNode.appendChild(cityNode);
 			
 			var wsdlFileNode=new Ext.tree.TreeNode({
 				id:idgen.newId(),
				text:'WSDLFile ['+action_wsdl_file+']',
				tag:'WSDLFile'
 			});
 			
 			var soapBindingName=new Ext.tree.TreeNode({
 				id:idgen.newId(),
				text:'SOAPBindingName ['+action_soap_binding+']',
				tag:'SOAPBindingName'
 			});
 			
 			var soapOperationName=new Ext.tree.TreeNode({
 				id:idgen.newId(),
				text:'SOAPOperationName ['+action_soap_operation+']',
				tag:'SOAPOperationName'
 			});
 			
 			var actionNode=new Ext.tree.TreeNode({
 				id:idgen.newId(),
				text:'Action ['+action_name+']',
				tag:'Action',
				attributes:actionAttr
 			});
 			actionNode.appendChild(wsdlFileNode);
 			actionNode.appendChild(soapBindingName);
 			actionNode.appendChild(soapOperationName);
 			
 			var partyNode=new Ext.tree.TreeNode({
 				text:type+' ['+name+']',
 				name:name,
 				tag:type,
 				attributes:partyAttr,
 				listeners:{
 					'contextmenu':function(node,e){
 						tree.selectedNode=node;
 						nodeOperationMenu.showAt(e.getXY());
 					}
 				}
 			});
 			partyNode.appendChild(contactNode);
 			partyNode.appendChild(actionNode);
 			
 			partiesNode.appendChild(partyNode);
 			
 			supportingPartyWin.hide();			
 			
 		}
 	}
 	]
});

var supportingPartyWin=new Ext.Window({
	id:'SupportingPartyWin',
	closeAction : 'hide', //这个很重要，为了防止关闭窗口后无法打开
	resizable : true,
	layout : 'fit',
	closable:true, 
	height:450,
	width:450,
	modal:true,
	items:[
	    supportingPartyPanel
	]
});

////////////////////////////////////////////// Schedule info///////////////////////////////////////////

var schedulePanel =new Ext.form.FormPanel({
	id:'SchedulePanel',
	frame:true,//圆角和浅蓝色背景
	blankText:'不允许为空',
	labelAlign:'right',
	monitorValid:true,
	defaults:{
		labelWidth:150
	},
	items:[
	{
		xtype:'textfield',
		id:'schedule_name',
		fieldLabel:'Name',
		name:'schedule_attr_name',
		width:200,
		enableKeyEvents:true,
		allowBlank:false
	}		
	,{
		xtype:'fieldset',
        title: 'Period',
        collapsible: true,
        autoHeight:true,
        width:420,
        defaults: {width: 200},
        defaultType: 'textfield',
        items :[
		new Ext.ux.form.DateTimeField({  
		    fieldLabel : 'Start',
		    name:'start_content',
		    emptyText : '请选择',  
		    //disabledDays : [1, 2, 5],//将星期一,二,五禁止.数值为0-6,0为星期日,6为星期六  
		    labelWidth : 150,  
		    //readOnly : true,  
		    //allowBlank : false,
		    id : 'schedule_start',  
		    //    vtype : 'daterange',//daterange类型为上代码定义的类型  
		    endDateField : 'schedule_end',//必须跟endDate的id名相同
		    dateFormat: 'Y-m-d',
		    timeFormat: 'H:i:s'
		})
		,new Ext.ux.form.DateTimeField({  
		    fieldLabel : 'End',  
		    name:'end_content',
		    emptyText : '请选择',  
		    //disabledDays : [1, 2, 5],//将星期一,二,五禁止.数值为0-6,0为星期日,6为星期六  
		    labelWidth : 150,  
		    //readOnly : true,  
		    //allowBlank : false,
		    id : 'schedule_end',  
		    //    vtype : 'daterange',//daterange类型为上代码定义的类型  
		    dateFormat: 'Y-m-d',
		    timeFormat: 'H:i:s'
		})
        ]
	}
	,{
		xtype:'fieldset',
        title: 'Interval',
        collapsible: true,
        autoHeight:true,
        width:420,
        defaults: {width: 200},
        defaultType: 'textfield',
        items :[
		new Ext.form.NumberField({
			id:'schedule_minutes',
            fieldLabel:'Minutes',
            name:'minutes_content',
            allowDecimals:false,               //不允许输入小数  
            nanText:'请输入有效整数',           //无效数字提示  
            allowNegative:false                //不允许输入负数  
        })
		,new Ext.form.NumberField({ 
			id:'schedule_seconds',
            fieldLabel:'Seconds',
            name:'seconds_content',
            allowDecimals:false,               //不允许输入小数  
            nanText:'请输入有效整数',           //无效数字提示  
            allowNegative:false,                //不允许输入负数  
            maxValue:59
        })
        ]
	}
	],
	buttons:[
 	{
 		formBind:true,
 		height : 20,
 		width : 50,
 		text : '添加',
 		action:'add',
 		handler: function() {
 			//关闭window，在tree上添加节点
 			if(this.action=='add'){
 				tree.selectedNode.appendChild(schedulePanel.getNode());
 			}else{
 				tree.selectedNode.remove();
 				serviceDefinitionNode.appendChild(schedulePanel.getNode());
 			}
 			
 			scheduleWin.hide();
 		}
 	}
 	],
 	getNode:function(){
 		var name=Ext.getCmp('schedule_name').getValue();
		var start=Ext.getCmp('schedule_start').getValue();
		var end=Ext.getCmp('schedule_end').getValue();
		var minutes=Ext.getCmp('schedule_minutes').getValue();
		var seconds=Ext.getCmp('schedule_seconds').getValue();
		
		var scheduleAttr=new HashMap();
		scheduleAttr.put('name',name);
		var startNode = new Ext.tree.TreeNode({
			id : idgen.newId(),
			text : 'Start [' + start + ']',
			tag : 'Start',
			content:start
		});

		var endNode = new Ext.tree.TreeNode({
			id : idgen.newId(),
			text : 'End [' + end + ']',
			tag : 'End',
			content:end
		});

		var periodNode = new Ext.tree.TreeNode({
			id : idgen.newId(),
			text : "Period",
			tag : "Period",
			attributes : new HashMap()
		});
		periodNode.appendChild(startNode);
		periodNode.appendChild(endNode);

		var minutesNode = new Ext.tree.TreeNode({
			id : idgen.newId(),
			text : 'Minutes [' + minutes + ']',
			tag : 'Minutes',
			content:minutes
		});

		var secondsNode = new Ext.tree.TreeNode({
			id : idgen.newId(),
			text : 'Seconds [' + seconds + ']',
			tag : 'Seconds',
			content:seconds
		});

		var intervalNode = new Ext.tree.TreeNode({
			id : idgen.newId(),
			text : 'Interval',
			tag : 'Interval'
		});
		intervalNode.appendChild(minutesNode);
		intervalNode.appendChild(secondsNode);

		var scheduleNode = new Ext.tree.TreeNode({
			text : 'Schedule [' + name + ']',
			name : name,
			tag : 'Schedule',
			attributes : scheduleAttr,
			listeners:{
				'contextmenu':function(node,e){
					tree.selectedNode=node;
					nodeOperationMenu.showAt(e.getXY());
				}
			}
		});
		scheduleNode.appendChild(periodNode);
		scheduleNode.appendChild(intervalNode);

		return scheduleNode;		
 	},
 	init:function(node){
 		var name=node.attributes.name;
		var type=node.attributes.tag;
		
		var partyAttr=node.attributes.attributes;
		var role=partyAttr.get('role');
		
		var contact=findChildByTag(node,'Contact');
		var city=findChildByTag(contact,'City').content;
		var street=findChildByTag(contact,'Street').content;
		
		var action=findChildByTag(node,'Action');
		var actionAttr=action.attributes.attributes;
		var action_name=actionAttr.get('name');
		var action_wsdl_file=findChildByTag(action,'WSDLFile').content;
		var action_soap_binding=findChildByTag(action,'SOAPBindingName').content;
		var action_soap_operation=findChildByTag(action,'SOAPOperationName').content;
 		
 		Ext.getCmp('supporting_party_name').setValue(name);
 		Ext.getCmp('supporting_party_role').setValue(role);
		Ext.getCmp('supporting_party_type').setValue(type);
		Ext.getCmp('supporting_party_city').setValue(city);		
		Ext.getCmp('supporting_party_street').setValue(street);
		
		Ext.getCmp('supporting_action_name').setValue(action_name);
		Ext.getCmp('supporting_action_wsdl_file').setValue(action_wsdl_file);
		Ext.getCmp('supporting_action_soap_binding').setValue(action_soap_binding);
		Ext.getCmp('supporting_action_soap_operation').setValue(action_soap_operation);
 	}
});
var scheduleWin=new Ext.Window({
	id:'ScheduleWin',
	closeAction : 'hide', //这个很重要，为了防止关闭窗口后无法打开
	resizable : true,
	layout : 'fit',
	closable:true, 
	height:450,
	width:450,
	modal:true,
	items:[
	    schedulePanel
	]
});

//////////////////////////////////////////////Metric info///////////////////////////////////////////
var metricPanel =new Ext.form.FormPanel({
	id:'MetricPanel',
	frame:true,//圆角和浅蓝色背景
	blankText:'不允许为空',
	labelAlign:'right',
	monitorValid:true,
	defaults:{
		labelWidth:150
	},
	items:[
	{
		xtype:'textfield',
		id:'metric_name',
		fieldLabel:'Name',
		name:'metric_attr_name',
		width:200,
		enableKeyEvents:true,
		allowBlank:false
	}		
	,{
		xtype:'textfield',
		id:'metric_type',
		fieldLabel:'Type',
		name:'metric_attr_type',
		width:200,
		enableKeyEvents:true,
		allowBlank:false
	}		
	,{
		xtype:'textfield',
		id:'metric_unit',
		fieldLabel:'Unit',
		name:'metric_attr_unit',
		width:200,
		enableKeyEvents:true,
		allowBlank:false
	}		
	,{
		xtype:'fieldset',
        title: 'Source',
        collapsible: true,
        autoHeight:true,
        width:420,
        defaults: {width: 200},
        defaultType: 'textfield',
        items :[
		{
			xtype:'textfield',
			id:'metric_source',
			fieldLabel:'Source',
			name:'source_content',
			width:200,
			enableKeyEvents:true,
			allowBlank:false
		}
        ]
	}
	],
	buttons:[
 	{
 		formBind:true,
 		height : 20,
 		width : 50,
 		text : '添加',
 		action:'add',
 		handler: function() {
 			//关闭window，在tree上添加节点
 			if(this.action=='add'){
 				tree.selectedNode.appendChild(metricPanel.getNode());
 			}else{
 				tree.selectedNode.remove();
 				serviceDefinitionNode.appendChild(metricPanel.getNode());
 			}
 			
 			metricWin.hide();
 		}
 	}
 	],
 	getNode:function(){
 		var name=Ext.getCmp('metric_name').getValue();
		var type=Ext.getCmp('metric_type').getValue();
		var unit=Ext.getCmp('metric_unit').getValue();
		var source=Ext.getCmp('metric_source').getValue();
		
		var metricAttr=new HashMap();
		metricAttr.put('name',name);
		metricAttr.put('type',type);
		metricAttr.put('unit',unit);
		var sourceNode = new Ext.tree.TreeNode({
			id : idgen.newId(),
			text : 'Source [' + source + ']',
			tag : 'Source',
			content:source
		});

		var metricNode = new Ext.tree.TreeNode({
			text : 'Metric [' + name + ']',
			name : name,
			tag : 'Metric',
			attributes : metricAttr,
			listeners:{
				'contextmenu':function(node,e){
					tree.selectedNode=node;
					nodeOperationMenu.showAt(e.getXY());
				}
			}
		});
		metricNode.appendChild(sourceNode);

		return metricNode;		
 	}
});
var metricWin=new Ext.Window({
	id:'MetricWin',
	closeAction : 'hide', //这个很重要，为了防止关闭窗口后无法打开
	resizable : true,
	layout : 'fit',
	closable:true, 
	height:450,
	width:450,
	modal:true,
	items:[
	    metricPanel
	]
});

//////////////////////////////////////////////Trigger info///////////////////////////////////////////
var triggerPanel =new Ext.form.FormPanel({
	id:'TriggerPanel',
	frame:true,//圆角和浅蓝色背景
	blankText:'不允许为空',
	labelAlign:'right',
	monitorValid:true,
	defaults:{
		labelWidth:150
	},
	items:[
	{
		xtype:'textfield',
		id:'trigger_name',
		fieldLabel:'Name',
		name:'trigger_attr_name',
		width:200,
		enableKeyEvents:true,
		allowBlank:false
	}		
	,{
		xtype:'fieldset',
        title: 'Time',
        collapsible: true,
        autoHeight:true,
        width:420,
        defaults: {width: 200},
        defaultType: 'textfield',
        items :[
		new Ext.ux.form.DateTimeField({  
		    fieldLabel : 'Time',  
		    name:'time_content',
		    emptyText : '请选择',  
		    //disabledDays : [1, 2, 5],//将星期一,二,五禁止.数值为0-6,0为星期日,6为星期六  
		    labelWidth : 150,  
		    //readOnly : true,  
		    //allowBlank : false,
		    id : 'trigger_time',  
		    //    vtype : 'daterange',//daterange类型为上代码定义的类型  
		    dateFormat: 'Y-m-d',
		    timeFormat: 'H:i:s'
		})
        ]
	}
	],
	buttons:[
 	{
 		formBind:true,
 		height : 20,
 		width : 50,
 		text : '添加',
 		action:'add',
 		handler: function() {
 			//关闭window，在tree上添加节点
 			if(this.action=='add'){
 				tree.selectedNode.appendChild(triggerPanel.getNode());
 			}else{
 				tree.selectedNode.remove();
 				serviceDefinitionNode.appendChild(triggerPanel.getNode());
 			}
 			
 			triggerWin.hide();
 		}
 	}
 	],
 	getNode:function(){
 		var name=Ext.getCmp('trigger_name').getValue();
		var time=Ext.getCmp('trigger_time').getValue();
		
		var triggerAttr=new HashMap();
		triggerAttr.put('name',name);
		var timeNode = new Ext.tree.TreeNode({
			id : idgen.newId(),
			text : 'Time [' + time + ']',
			tag : 'Time',
			content:time
		});

		var triggerNode = new Ext.tree.TreeNode({
			text : 'Trigger [' + name + ']',
			name : name,
			tag : 'Trigger',
			attributes : triggerAttr,
			listeners:{
				'contextmenu':function(node,e){
					tree.selectedNode=node;
					nodeOperationMenu.showAt(e.getXY());
				}
			}
		});
		triggerNode.appendChild(timeNode);

		return triggerNode;		
 	}
});
var triggerWin=new Ext.Window({
	id:'TriggerWin',
	closeAction : 'hide', //这个很重要，为了防止关闭窗口后无法打开
	resizable : true,
	layout : 'fit',
	closable:true, 
	height:450,
	width:450,
	modal:true,
	items:[
	    triggerPanel
	]
});

//////////////////////////////////////////////Constant info///////////////////////////////////////////
var constantPanel =new Ext.form.FormPanel({
	id:'ConstantPanel',
	frame:true,//圆角和浅蓝色背景
	blankText:'不允许为空',
	labelAlign:'right',
	monitorValid:true,
	defaults:{
		labelWidth:150
	},
	items:[
	{
		xtype:'textfield',
		id:'constant_name',
		fieldLabel:'Name',
		name:'constant_attr_name',
		width:200,
		enableKeyEvents:true,
		allowBlank:false
	}		
	,{
		xtype:'fieldset',
		id:'constant_type_fieldset',
        title: 'Value',
        layout:'form',
        collapsible: true,
        autoHeight:true,
        width:420,
        defaults: {width: 200},
        defaultType: 'textfield',
		items : [ {
			xtype : 'combo',
			id : 'constant_type',
			fieldLabel : 'Type',
			name : '_constant_type',
			store : new Ext.data.SimpleStore({
				fields : [ 'text' ],
				data : [ [ 'String' ], [ 'Integer' ], [ 'Float' ] ]
			}),
			valueField : "text",
			displayField : "text",
			editable : false,
			forceSelection : true,
			typeAhead : true,
			triggerAction : 'all',
			selectOnFocus : true,// 用户不能自己输入,只能选择列表中有的记录
			allowBlank : false,
			mode : 'local',
			displayed:false,
			emptyText : '请选择Constant类型',
			listeners : {
				'afterRender' : function(combo) {
					var firstValue = this.store.getRange()[0].data.text;
					this.setValue(firstValue);// 同时下拉框会将与name为firstValue值对应的
												// text显示
				},
				'select' : function(field,record,index){
					var fs=Ext.getCmp('constant_type_fieldset');
					var type=record.get('text');
					
					fs.switchValueField(type);
				}
			}
		} ],
		switchValueField:function(type){
			var valueField=Ext.getCmp('constant_value');
			if(valueField!=undefined){
				this.remove(valueField,true);
				//fs.doLayout();
			}
			
			var newValueField;
			if(type=='String'){
				newValueField=new Ext.form.TextField({
					id:'constant_value',
					name:'value_content',
					fieldLabel:'String',
					width:200,
					enableKeyEvents:true,
					allowBlank:false
				});
			}else if(type=='Integer'){
				newValueField=new Ext.form.NumberField({
					id:'constant_value',
		            fieldLabel:'Integer',
		            name:'value_content',
		            allowBlank:false,
		            allowDecimals:false,               //不允许输入小数  
		            nanText:'请输入有效整数',           //无效数字提示  
		            allowNegative:true                //不允许输入负数  
		            //maxValue:59
				});
			}else if(type=='Float'){
				newValueField=new Ext.form.NumberField({
					id:'constant_value',
		            fieldLabel:'Float',
		            name:'value_content',
		            allowDecimals:true,               //不允许输入小数  
		            nanText:'请输入有效整数',           //无效数字提示  
		            allowNegative:true,                //不允许输入负数  
		            allowBlank:false
		            //maxValue:59
				});
			}
			
			this.add(newValueField);
			this.doLayout();

			//constantPanel.doLayout();
			//constantWin.doLayout();
		}
	}
	],
	buttons:[
 	{
 		formBind:true,
 		height : 20,
 		width : 50,
 		text : '添加',
 		action:'add',
 		handler: function() {
 			//关闭window，在tree上添加节点
 			if(this.action=='add'){
 				tree.selectedNode.appendChild(constantPanel.getNode());
 			}else{
 				tree.selectedNode.remove();
 				serviceDefinitionNode.appendChild(constantPanel.getNode());
 			}
 			
 			constantWin.hide();
 		}
 	}
 	],
 	getNode:function(){
 		var name=Ext.getCmp('constant_name').getValue();
		var type=Ext.getCmp('constant_type').getValue();
 		var value=Ext.getCmp('constant_value').getValue();
		
		var constantAttr=new HashMap();
		constantAttr.put('name',name);
		var valueNode = new Ext.tree.TreeNode({
			id : idgen.newId(),
			text : type+' [' + value + ']',
			tag : type,
			content:value
		});

		var constantNode = new Ext.tree.TreeNode({
			text : 'Constant [' + name + ']',
			name : name,
			tag : 'Constant',
			attributes : constantAttr,
			listeners:{
				'contextmenu':function(node,e){
					tree.selectedNode=node;
					constantOperationMenu.showAt(e.getXY());
				}
			}
		});
		constantNode.appendChild(valueNode);

		return constantNode;		
 	},
 	initiateForm:function(){
 		var node=tree.selectedNode;
		var name=node.attributes.name;
		
		//constantPanel.form.reset();
		
		var btn=constantPanel.buttons[0];
		btn.setText('编辑');
		btn.action='edit';
		
		//set name
		Ext.getCmp('constant_name').setValue(name);
		var typeCombo=Ext.getCmp('constant_type');
		
//		//set type
//		node.eachChild(function(child){
//			typeCombo.selectByValue(child.attributes.tag);
//			//set value
//			var valueField=Ext.getCmp('constant_value');
//			valueField.setValue(child.attributes.content);
//		});
		
		
		var children=node.childNodes;
		var child=children[0];
		typeCombo.setValue(child.attributes.tag);
		
		var fs=Ext.getCmp('constant_type_fieldset');		
		fs.switchValueField(child.attributes.tag);
		
		
		//set value
		var valueField=Ext.getCmp('constant_value');
		valueField.setValue(child.attributes.content);
 	}
});
var constantWin=new Ext.Window({
	id:'ConstantWin',
	closeAction : 'hide', //这个很重要，为了防止关闭窗口后无法打开
	resizable : true,
	layout : 'fit',
	closable:true, 
	height:450,
	width:450,
	modal:true,
	items:[
	    constantPanel
	]
});

var constantOperationMenu=new Ext.menu.Menu({
	id : 'nodeOperationMenu',
	items : [ {
		//xtype : "button",
		text : "编辑节点信息",
		iconCls : "edit",
		pressed : true,
		handler : function(){
			constantWin.show();
			constantPanel.initiateForm();			
			
		}
	},{
		//xtype : "button",
		text : "删除节点",
		iconCls : "delete",
		pressed : true,
		handler : function(){
			var node=tree.selectedNode;
			node.remove();
		}
	}]
});

//////////////////////////////////////////////SLAParameter info///////////////////////////////////////////
var slaParameterPanel =new Ext.form.FormPanel({
	id:'SLAParameterPanel',
	frame:true,//圆角和浅蓝色背景
	blankText:'不允许为空',
	labelAlign:'right',
	monitorValid:true,
	defaults:{
		labelWidth:150
	},
	items:[
	{
		xtype:'textfield',
		id:'slaparameter_name',
		fieldLabel:'Name',
		name:'slaparameter_attr_name',
		width:200,
		enableKeyEvents:true,
		allowBlank:false
	}
	,{
		xtype:'textfield',
		id:'slaparameter_type',
		fieldLabel:'Type',
		name:'slaparameter_attr_type',
		width:200,
		enableKeyEvents:true,
		allowBlank:false
	}		
	,{
		xtype:'textfield',
		id:'slaparameter_unit',
		fieldLabel:'Unit',
		name:'slaparameter_attr_unit',
		width:200,
		enableKeyEvents:true,
		allowBlank:false
	}
	,{
		xtype:'fieldset',
        title: 'Metric',
        collapsible: true,
        autoHeight:true,
        width:420,
        defaults: {width: 200},
        defaultType: 'textfield',
        items :[
		{  
			xtype:'textfield',
		    fieldLabel : 'Metric',  
		    name:'metric_content',
		    labelWidth : 150,  
		    //readOnly : true,  
		    allowBlank : false,
		    id : 'slaparameter_metric',
		    width:200
		}
        ]
	}
	,{
		xtype:'fieldset',
        title: 'Communication',
        collapsible: true,
        autoHeight:true,
        width:420,
        defaults: {width: 200},
        defaultType: 'textfield',
        items :[
		{  
			xtype:'textfield',
		    fieldLabel : 'Source',  
		    name:'source_content',
		    labelWidth : 150,  
		    //readOnly : true,  
		    allowBlank : false,
		    id : 'slaparameter_source',
		    width:200
		}
		,{  
			xtype:'textfield',
		    fieldLabel : 'Pull',  
		    name:'pull_content',
		    labelWidth : 150,  
		    //readOnly : true,  
		    allowBlank : false,
		    id : 'slaparameter_pull',
		    width:200
		}
		,{  
			xtype:'textfield',
		    fieldLabel : 'Push',  
		    name:'push_content',
		    labelWidth : 150,  
		    //readOnly : true,  
		    allowBlank : false,
		    id : 'slaparameter_push',
		    width:200
		}
        ]
	}
	],
	buttons:[
 	{
 		formBind:true,
 		height : 20,
 		width : 50,
 		text : '添加',
 		action:'add',
 		handler: function() {
 			//关闭window，在tree上添加节点
 			if(this.action=='add'){
 				tree.selectedNode.appendChild(slaParameterPanel.getNode());
 			}else{
 				tree.selectedNode.remove();
 				serviceDefinitionNode.appendChild(slaParameterPanel.getNode());
 			}
 			
 			slaParameterWin.hide();
 		}
 	}
 	],
 	getNode:function(){
 		var name=Ext.getCmp('slaparameter_name').getValue();
		var type=Ext.getCmp('slaparameter_type').getValue();
		var unit=Ext.getCmp('slaparameter_unit').getValue();		
		var metric=Ext.getCmp('slaparameter_metric').getValue();
		var source=Ext.getCmp('slaparameter_metric').getValue();
		var pull=Ext.getCmp('slaparameter_pull').getValue();
		var push=Ext.getCmp('slaparameter_push').getValue();
		
		var slaParameterAttr=new HashMap();
		slaParameterAttr.put('name',name);
		slaParameterAttr.put('type',type);
		slaParameterAttr.put('unit',unit);
		
		var metricNode = new Ext.tree.TreeNode({
			id : idgen.newId(),
			text : 'Metric [' + metric + ']',
			tag : 'Metric',
			content:metric
		});
		
		var sourceNode = new Ext.tree.TreeNode({
			id : idgen.newId(),
			text : 'Source [' + source + ']',
			tag : 'Source',
			content:source
		});
		
		var pullNode = new Ext.tree.TreeNode({
			id : idgen.newId(),
			text : 'Pull [' + pull + ']',
			tag : 'Pull',
			content:pull
		});
		
		var pushNode = new Ext.tree.TreeNode({
			id : idgen.newId(),
			text : 'Push [' + push + ']',
			tag : 'Push',
			content:push
		});
		
		var communicationNode = new Ext.tree.TreeNode({
			id : idgen.newId(),
			text : 'Communication',
			tag : 'Communication',
			attributes:new HashMap()
		});
		communicationNode.appendChild(sourceNode);
		communicationNode.appendChild(pullNode);
		communicationNode.appendChild(pushNode);

		var slaParameterNode = new Ext.tree.TreeNode({
			text : 'SLAParameter [' + name + ']',
			name : name,
			tag : 'SLAParameter',
			attributes : slaParameterAttr,
			listeners:{
				'contextmenu':function(node,e){
					tree.selectedNode=node;
					nodeOperationMenu.showAt(e.getXY());
				}
			}
		});
		slaParameterNode.appendChild(metricNode);
		slaParameterNode.appendChild(communicationNode);

		return slaParameterNode;		
 	}
});
var slaParameterWin=new Ext.Window({
	id:'SLAParameterWin',
	closeAction : 'hide', //这个很重要，为了防止关闭窗口后无法打开
	resizable : true,
	layout : 'fit',
	closable:true, 
	height:450,
	width:450,
	modal:true,
	items:[
	    slaParameterPanel
	]
});
